//
//  SettingViewController.m
//  e-nurse
//
//  Created by  on 10/10/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "SettingViewController.h"
#import "ProfileViewController.h"
#import "AlarmViewController.h"
#import "KnowledgeViewController.h"
#import "FeedbackViewController.h"

@interface SettingViewController ()

@property (strong, nonatomic) NSMutableArray* subsettingViewControls;

-(void)loadSubsettingViewControls;

@end

@implementation SettingViewController
@synthesize subsettingViewControls = _subsettingViewControls;

- (void)dealloc
{
    self.subsettingViewControls = nil;
    [super dealloc];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self loadSubsettingViewControls];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    
    self.subsettingViewControls = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark Table Methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [self.subsettingViewControls count];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return @"";
}

- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section 
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    static NSString *SettingTableIdentifier = @"SettingTableIdentifier";
    
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: SettingTableIdentifier];
    
    if(cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SettingTableIdentifier] autorelease];
    }
    
    UIViewController* settingVC = [self.subsettingViewControls objectAtIndex:indexPath.section];
    cell.textLabel.text = settingVC.title;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    [self.navigationController pushViewController:[self.subsettingViewControls objectAtIndex:indexPath.section] animated:YES];
}

- (void)loadSubsettingViewControls
{
    self.subsettingViewControls = nil;
    
    self.subsettingViewControls = [[[NSMutableArray alloc] init] autorelease];
    
    ProfileViewController* profileVC = [[ProfileViewController alloc] initWithNibName:@"ProfileViewController" bundle:nil];
    [self.subsettingViewControls addObject:profileVC];
    [profileVC release];
    
    AlarmViewController* alarmVC = [[AlarmViewController alloc] initWithNibName:@"AlarmViewController" bundle:nil];
    [self.subsettingViewControls addObject:alarmVC];
    [alarmVC release];
    
    KnowledgeViewController* knowledgeVC = [[KnowledgeViewController alloc] initWithNibName:@"KnowledgeViewController" bundle:nil];
    [self.subsettingViewControls addObject:knowledgeVC];
    [knowledgeVC release];
    
    FeedbackViewController* feedbackVC = [[FeedbackViewController alloc] initWithNibName:@"FeedbackViewController" bundle:nil];
    [self.subsettingViewControls addObject:feedbackVC];
    [feedbackVC release];
}

@end
